home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Uso de la consola / CppDateStruct / CppDateStruct.cpp next >
Encoding:
C/C++ Source or Header  |  2002-07-15  |  785 b   |  35 lines

  1. //---------------------------------------------
  2. // CppDateStruct.cpp ⌐ 2001 by Charles Petzold
  3. //---------------------------------------------
  4. #include <stdio.h>
  5.  
  6. struct Date
  7. {
  8.      int year;
  9.      int month;
  10.      int day;
  11.  
  12.      int IsLeapYear()
  13.      {
  14.           return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
  15.      }
  16.      int DayOfYear()
  17.      {
  18.           static int MonthDays[12] = {   0,  31,  59,  90, 120, 151,
  19.                                        181, 212, 243, 273, 304, 334 };
  20.  
  21.           return MonthDays[month - 1] + day + ((month > 2) && IsLeapYear());
  22.      }
  23. };
  24. int main(void)
  25. {
  26.     Date mydate;
  27.  
  28.     mydate.month = 8;
  29.     mydate.day   = 29;
  30.     mydate.year  = 2001;
  31.  
  32.     printf("Dφa del a±o = %i\n", mydate.DayOfYear());
  33.  
  34.     return 0;
  35. }